﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using iuPlace.Web.Models;
using System.Web.Mvc;

namespace iuPlace.Web.Extensions
{
    public static class Controller
    {
        public static View CreateViewModel(this iuPlace.Web.Controllers.BaseController controller)
        {
            View viewModel = new View();
            viewModel.Version = controller.GetType().Assembly.GetName().Version.ToString();
            viewModel.Session = iuPlaceApplication.Current.CurrentSession;
            return viewModel;
        }

        public static CacheResult CreateCacheResult(this iuPlace.Web.Controllers.BaseController controller, string version, IEnumerable<string> cacheAssets, IEnumerable<string> networkAssets, Dictionary<string, string> fallbackAssets)
        {
            CacheResult result = new CacheResult();
            result.Version = version;
            result.CacheAssets = new List<string>(cacheAssets);
            result.NetworkAssets = new List<string>(networkAssets);
            result.FallbackAssets = fallbackAssets;
            return result;
        }

        public static JsonResult JsonResultData(this iuPlace.Web.Controllers.BaseController controller, object data)
        {
            JsonResult result = new JsonResult();
            result.Data = new JsonResultData(data);            
            result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            return result;
        }
    }
}